package com.feihao.zhou.demo01;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

public class ThreadPoolTest2 {
    public static void main(String[] args) {
        //创建指定线程个数上线的线程池；
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        ThreadPoolExecutor pool = (ThreadPoolExecutor) executorService;

        pool.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("线程执行");
            }
        });
        pool.submit(() -> {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程执行Callable");
            return "顶顶顶";
        });

        pool.submit(() -> {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Runnable执行");
        });
        System.out.println("线程池的线程个数" + pool.getPoolSize());

        executorService.shutdown();
    }
}
